package com.HospitalOutpatient.controller;

import com.HospitalOutpatient.annotation.LoginToken;
import com.HospitalOutpatient.entity.Doctor;
import com.HospitalOutpatient.entity.Outpatient;
import com.HospitalOutpatient.service.DoctorService;
import com.HospitalOutpatient.service.OutpatientService;
import com.HospitalOutpatient.vo.DoctorAndOutpatientAndUser;
import com.HospitalOutpatient.vo.OutpatientAndDepartName;
import com.HospitalOutpatient.vo.OutpatientValue;
import com.HospitalOutpatient.vo.OutpatientVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/outpatient")
public class OutpatientController {

    @Autowired
    private OutpatientService outpatientService;
    @LoginToken
    @GetMapping("/getAllOutpatient")
    public Result getAllOutpatient(){
        List<OutpatientValue> outpatientValueList = outpatientService.getAllOutpatient();

        return new Result(Code.GET_OK,outpatientValueList,"门诊信息");
    }
    @LoginToken
    @GetMapping("/getAllOutpatientTree")
    public Result getAllOutpatientTree(){
        List<OutpatientVo> outpatients = outpatientService.getAllOutpatientByDepartmentId();

        return new Result(Code.GET_OK,outpatients,"树形门诊信息");
    }
    @LoginToken
    @GetMapping("/getAllOutpatientAndDepartName")
    public Result getAllOutpatientAndDepartName(){
        List<OutpatientAndDepartName> list = outpatientService.getAllOutpatientAndDepartName();
        return new Result(Code.GET_OK,list,"门诊关联科室信息");
    }
    @LoginToken
    @PostMapping("/addOutpatient")
    public Result addOutpatient(@RequestBody Outpatient outpatient){
        boolean b = outpatientService.addOutpatient(outpatient);
        if(b == false){
            return new Result(Code.SAVE_ERR,null,"添加门诊信息失败");
        }
        return new Result(Code.SAVE_OK,null,"添加门诊信息成功");
    }
    @LoginToken
    @PostMapping("/editOutpatient")
    public Result editOutpatient(@RequestBody Outpatient outpatient){
        boolean b = outpatientService.editOutpatient(outpatient);
        if(b == false){
            return new Result(Code.UPDATE_ERR,null,"添加门诊信息失败");
        }
        return new Result(Code.UPDATE_OK,null,"添加门诊信息成功");
    }

}
